--
module("UI.Windows.ZhuanRuZhuanChuWin", package.seeall)

local UIUtility = require("UI.Utility")
local UIWindow = require("UI.UIWindow").UIWindow
local UIWinMgr = require("UI.UIWinMgr").UIWinMgr
local json = require("cjson")
ZhuanRuZhuanChuWin = UIWindow:new()

ZhuanRuZhuanChuWin.name = "ZhuanRuZhuanChuWin"

local GameObject = UnityEngine.GameObject


function ZhuanRuZhuanChuWin:Init()
    local t = self.Container.transform

    self.close_btn = UIUtility.GetChildTransform("close_btn", t, true)
    self:BindEvents()
    self.tag_lable = UIUtility.FindContorl("UILabel", "tag_lable", t)
    self.jine_input_lable = UIUtility.FindContorl("UILabel", "jine_input_lable", t)
    self.jine_input = UIUtility.FindContorl("UIInput", "jine_input", t)
    self.tips_lable = UIUtility.FindContorl("UILabel", "tips_lable", t)
    self.tag_index = 0
    UIHelper.BindUIEvnet("Click", function()
    if self.jine_input.value == "" then
        UIWinMgr:OpenTextNotice("请输入金额")
        return
    end

        local data 
        if self.tag_index == 1 then
        data= string.format(
            '{"fromWalletType":%s,"toWalletType":%s,"amount":%s}',
            3, 1, tonumber(self.jine_input.value)*100)
        else
            data = string.format(
                '{"fromWalletType":%s,"toWalletType":%s,"amount":%s}',
                1, 3, tonumber(self.jine_input.value)*100)
        end

        require("NetWork.NetHttp").SendPostRequest_token("/byr/wallet/transfer",
            function(ok, data)
                if ok then
                    print("请求转账:" .. stringify(data))
                    UIWinMgr:OpenTextNotice("转账完成")
                    require("UI.Windows.NewGameLoobyWin").NewGameLoobyWin:UpdateUserInfo()
                    self:Close()
                else
                    print("请求转账失败:" .. stringify(data))
                    UIWinMgr:OpenTextNotice(data.msg)
                end
            end,
            data
        )
    end, UIUtility.GetChildTransform("queren_btn", t, true).gameObject)
end

function ZhuanRuZhuanChuWin:OnShow()
   
end

function ZhuanRuZhuanChuWin:SetTag(_tag)
    self.tag_index = _tag
    self.balance_data=require("UI.Windows.NewGameLoobyWin").NewGameLoobyWin.balance_data
    self.jine_input.value=""
    if _tag == 1 then
        self.tag_lable.text = "转出"
        self.jine_input_lable.text = "请输入转出金额"
        self.tips_lable.text = "转出金额不能超过" .. self.balance_data.policyBalance / 100
    else
        self.tag_lable.text = "转入"
        self.jine_input_lable.text = "请输入转入金额"
        self.tips_lable.text = "转入额度为" .. self.balance_data.withdrawBalance / 100
    end
end

function ZhuanRuZhuanChuWin:OnClose()

end

function ZhuanRuZhuanChuWin:BindEvents()
    UIHelper.BindUIEvnet("Click", function()
        self:Close()
    end, self.close_btn.gameObject)
end
